* myrifreg.ado 	JEP		01/24/15
* Program to do recentered influence function regression, very simple

*************************** Change log ********************************** 

/*
	01/25/15	Suppress display of regression
*/

program define myrifreg, eclass
	version 13.1
	syntax varlist(fv) [if] [in] [pw], q(integer) rif(name) cluster(varname) [bw(passthru) kernel(string)]
	tempvar atx dy T 
	* Marksample	
	marksample touse
	* Separate dep and indep
	gettoken lhs rhs: varlist
	_pctile `lhs' if `touse', p(`q')
	loc p=r(r1)
	* cap drop atx
	qui gen `atx'=`p' in 1/1
	* cap drop dy
	* Defaults
	if "`bw'"=="" loc bw "silverman"
	if "`kernel'"=="" loc kernel "gaussian"
	qui kdens `lhs' if `touse', gen(`dy') kernel(`kernel') bw(`bw') nograph at(`atx') 
	* RIF
	gen `T'= (`lhs'>`p')
	qui sum `dy' in 1/1, meanonly
	loc fy=r(mean)
	gen `rif'=`p' + `T'/`fy' if `touse'
	* RIF = p + T/fy - 1/fy * (1-q) but last term is a constant, so no problem.
	quietly reg `rif' `rhs' [`weight'`exp'] if `touse' , cluster(`cluster')
end
